import ajax from '@util/ajax.ts'
import { Result } from '@src/interfaces/TypeResult.ts'
// 得到全部缴费记录
export const getPaymentRecordByClassIdApi = (page: number, size: number) => {
  let param = new URLSearchParams()
  param.append('page', page)
  param.append('size', size)
  return ajax.get(`/payment-record/classId`, {
    params: param,
  })
}
// 获取单个用户缴费记录
export const getPaymentRecordByUserIdApi = (page: number, size: number) => {
  let param = new URLSearchParams()
  param.append('page', page)
  param.append('size', size)
  return ajax.get(`/payment-record/userId`, {
    params: param,
  })
}
// 缴费
export const paymentApi = (paymentProjectId: number, imageName: string) => {
  const data = {
    paymentProjectId: paymentProjectId,
    imageName: imageName,
  }
  return ajax.post(`/payment-project/pay`, data)
}
// 获取缴费项目信息
export const getPaymentProjectInfoByIdApi = (paymentProjectId: number) => {
  return ajax.get(`/payment-project/${paymentProjectId}`)
}
//搜索缴费项目（也可以查询全部缴费信息）
export const getAllPaymentProjectByIdApi = (
  page: number,
  size: number,
  text: string,
) => {
  const param = new URLSearchParams()
  param.append('page', page)
  param.append('size', size)
  param.append('text', text)
  return ajax.get(`/payment-project/classId`, {
    params: param,
  })
}
// 删除缴费项目
export const deletePaymentProjectApi = (paymentProjectId: number) => {
  return ajax.delete(`/payment-project/${paymentProjectId}`)
}
//添加缴费项目
export const addPaymentProjectApi = (data: object) => {
  return ajax.post(`/payment-project`, data)
}
//修改缴费项目
export const updatePaymentProjectApi = (data: object) => {
  return ajax.put(`/payment-project`, data)
}
//是否交过该缴费项目费用
export const isPaidApi = (paymentProjectId: number) => {
  const param = new URLSearchParams()
  param.append('paymentProjectId', paymentProjectId)
  return ajax
    .get('/payment-record/isPaid', {
      params: param,
    })
    .then((res) => {
      return res.data as Result<boolean>
    })
}
